Learn T-SQL Commands with Samples
Skip Navigation Links
Skip Navigation Links.
Expand DatabaseDatabase
Expand TableTable
Expand ViewView
Expand Stored ProcedureStored Procedure
Expand Data FilteringData Filtering
Expand Data GroupingData Grouping
Expand JoinsJoins
Expand TriggerTrigger
Expand CursorCursor
Expand OperatorsOperators
Expand ConstraintsConstraints
Expand FunctionsFunctions
Expand Conditional ProcessingConditional Processing
Expand LoopingLooping
Expand Error HandlingError Handling
Collapse v.IMP Queriesv.IMP Queries
Expand XMLXML
Expand Query PerformanceQuery Performance
Expand QueriesQueries
Expand NormalizationNormalization
Expand CreateCreate
     

Sort Rows in Specific Order

 
EMP
ID Name Country Salary
1 Vijay India 6000
2 Bill USA 8000
3 Kris France 3000
      
---- Ascending Order
SELECT Country FROM EMP ORDER BY Country ASC
---- Descending Order
SELECT Country FROM EMP ORDER BY Country DESC
---- Specific Order
SELECT *, CASE Country WHEN 'France' THEN 1 WHEN 'India' THEN 2 WHEN 'USA' THEN 3 END AS 'MyOwnOrder' FROM EMP ORDER BY MySpecificOrder
      
Output
ID Name Country Salary MySpecificOrder
3 Kris France 3000 1
1 Vijay India 6000 2
2 Bill USA 8000 3